package com.rocksdata.mc.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.ctz.commonframe.utils.GlideApp;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.rocksdata.mc.entity.BannerInfo;

import java.util.List;

public class BannerListAdapter extends StaticPagerAdapter {
    private List<BannerInfo> dataList;
    private Context context;

    public BannerListAdapter(Context context, List<BannerInfo> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public View getView(ViewGroup container, int position) {
        ImageView view = new ImageView(context);
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

//        if (Config.isDebug)
//            view.setImageResource(dataList.get(position).imageRes);
//        else
//            XUtils3ImageDisplayer.display(view, dataList.get(position).imageUrl);
        GlideApp.with(context).load(dataList.get(position).imageUrl)
                .placeholder(dataList.get(position).imageRes)
                .error(dataList.get(position).imageRes)
                .fallback(dataList.get(position).imageRes)
                .into(view);
        return view;
    }
}